<?php

namespace App\Models\Strator;

use App\Models\Traits\DateTimeTrait;
use App\Models\Traits\ModelSearchTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class StratorPosition extends Model
{
    use SoftDeletes, DateTimeTrait, ModelSearchTrait;

    protected $dateFormat = 'Y-m-d H:i:s';
    protected $guarded = [];

    //
    public function searchConditions():array{
        return [
            ['position_name','like'],
            ['position_code','='],
            ['department_id','='],
        ];
    }

    //
    public function department(){
        return $this->belongsTo(StratorDepartment::class,'department_id','id');
    }

    //
    public function permissions():BelongsToMany{
        return $this->belongsToMany(StratorPermission::class,'strator_position_has_permissions','position_id','permission_id','id','id')->wherePivotNull('deleted_at');
    }


}
